/**
 * 
 */
package com.coral.fundation.user.impl;

import java.sql.Connection;
import java.sql.PreparedStatement;

import com.coral.fundation.dao.impl.BasicDao;
import com.coral.fundation.db.SQLiteDataSource;
import com.coral.fundation.db.UUIDCreator;
import com.coral.fundation.user.entity.User;

/**
 * @author Coral
 *
 */
public class UserDaoImpl extends BasicDao {
	
	User rsUser = null;
	
	public User saveUser(final User user) throws Exception {
		Connection con = SQLiteDataSource.getConnection();
		if(user.getUserId() == null) {
			user.setUserId(UUIDCreator.getID());
		}
		String sql = "insert into t_user values(?,?,?,?,?)";
		PreparedStatement pstm=con.prepareStatement(sql);
		pstm.setString(1, user.getUserId());
		pstm.setString(2, user.getUserName());
		pstm.setString(3, user.getPassword());
		pstm.setInt(4, user.getIsValid());
		pstm.setInt(5, user.getErrTimes());
		pstm.execute();
		return rsUser;
	}
}
